home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / security / xinetd / sio.1.5.6 / suite / fdtest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-09  |  1.1 KB  |  72 lines

  1. /*
  2.  * (c) Copyright 1992 by Panagiotis Tsirigotis
  3.  * All rights reserved.  The file named COPYRIGHT specifies the terms 
  4.  * and conditions for redistribution.
  5.  */
  6.  
  7.  
  8. #include <sys/time.h>
  9. #include <sys/resource.h>
  10.  
  11. #include "sio.h"
  12.  
  13. #ifndef NULL
  14. #define NULL 0
  15. #endif
  16.  
  17. int main( argc, argv )
  18.     int argc ;
  19.     char *argv[] ;
  20. {
  21. #ifdef RLIMIT_NOFILE
  22.     struct rlimit rl ;
  23.     int fd ;
  24.     int duped_fd ;
  25.     char *s ;
  26.  
  27.     if ( getrlimit( RLIMIT_NOFILE, &rl ) == -1 )
  28.     {
  29.         perror( "getrlimit" ) ;
  30.         exit( 1 ) ;
  31.     }
  32.     if ( rl.rlim_cur != getdtablesize() )
  33.     {
  34.         printf( "rl.rlim_cur != getdtablesize()\n" ) ;
  35.         exit( 1 ) ;
  36.     }
  37.     rl.rlim_cur++ ;
  38.     if ( setrlimit( RLIMIT_NOFILE, &rl ) == -1 )
  39.     {
  40.         perror( "setrlimit" ) ;
  41.         exit( 1 ) ;
  42.     }
  43.     if ( Smorefds() == SIO_ERR )
  44.     {
  45.         perror( "Smorefds" ) ;
  46.         exit( 1 ) ;
  47.     }
  48.     fd = open( "/etc/passwd", 0 ) ;
  49.     if ( fd == -1 )
  50.     {
  51.         perror( "open" ) ;
  52.         exit( 1 ) ;
  53.     }
  54.     duped_fd = getdtablesize()-1 ;
  55.     if ( dup2( fd, duped_fd ) == -1 )
  56.     {
  57.         perror( "dup2" ) ;
  58.         exit( 1 ) ;
  59.     }
  60.     s = Srdline( duped_fd ) ;
  61.     if ( s == NULL )
  62.     {
  63.         perror( "Srdline" ) ;
  64.         exit( 1 ) ;
  65.     }
  66.     printf( "Test PASSED\n" ) ;
  67. #else
  68.     printf( "Test PASSED\n" ) ;
  69. #endif
  70.     exit( 0 ) ;
  71. }
  72.